home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / patch / ppak25_1.lha / PhonePak_2.5 / rexxFaxOnDemand.ppak < prev    next >
Text File  |  1994-07-09  |  8KB  |  185 lines

  1. /************************************************************************/
  2. /*  FaxOnDemand.ppak         Copyright 1994 Atlantis Design Group, Inc. */
  3. /*                                                                      */
  4. /*  This ARexx script for PhonePak implements a one-call fax on demand  */
  5. /*  system.  To use this script, create a mailbox that you can get to   */
  6. /*  via normal system routing.  Put a greeting in the mailbox that      */
  7. /*  informs callers that they must be calling from a fax machine and    */
  8. /*  tells them how many faxes they can request.  You might then         */
  9. /*  identify some of the more often-requested faxes, including a fax    */
  10. /*  which contains a description and an ID number for all available     */
  11. /*  faxes.  You should then prompt the caller to enter the number of    */
  12. /*  the first fax they want to receive.  All of the available faxes     */
  13. /*  should be placed in the mailbox, and the filename of each fax       */
  14. /*  should correspond to the number the caller enters to retrieve it.   */
  15. /*  Finally, you should set up the ARexx Route Host for the mailbox as  */
  16. /*  "FAXONDEMAND", and run this script as part of your normal system    */
  17. /*  startup procedure.  This script will take over the call when the    */
  18. /*  caller makes his/her first selection.  The MAXFAXES variable below  */
  19. /*  can be adjusted to limit the number of faxes that can be retrieved  */
  20. /*  in a single session.  This script is set up for single line use.    */
  21. /*  The filenote of each fax will be used to keep track of the number   */
  22. /*  of times that fax has been successfully transmitted.                */
  23. /************************************************************************/
  24.  
  25. /************************************************************************/
  26. /*  Messages needed by this script; put them in fax mailbox, too:       */
  27. /*                                                                      */
  28. /*  YouHaveEntered.sys - "You Have Entered..."                          */
  29. /*  IfCorrect.sys - "If this is correct, press 1."                      */
  30. /*  Invalid.sys - "I'm sorry, you have made an invalid selection."      */
  31. /*  NextDocument.sys - "Please enter the number of the next document    */
  32. /*      you wish to receive, or if you are ready to receive the         */
  33. /*      information you have requested, press star."                    */
  34. /************************************************************************/
  35.  
  36. MAXFAXES = 3
  37. PortName = "FAXONDEMAND"    /* No line number appended */
  38.  
  39. options results
  40. call addlib('rexxsupport.library',0,-30,0)
  41. call openport(PortName)
  42.  
  43. address LINEMAN.1           /* We're going to talk to line 1 */
  44.  
  45. /************************************************************************/
  46. /*  MAIN LOOP                                                           */
  47. /************************************************************************/
  48. do forever
  49.     call waitpkt(PortName)
  50.     Pkt = getpkt(PortName)
  51.     if Pkt = null() then
  52.         iterate
  53.     
  54.     Arg = getarg(Pkt,0)
  55.     parse var Arg . Line Mailbox Code
  56.  
  57.     Code = strip(Code)          /* get rid of leading/trailing spaces */
  58.     SETMAILBOX Mailbox          /* Get mailbox info */
  59.     Path = strip(word(result,1),,"'")
  60.     call pragma('d',Path)       /* CD this script to mb directory to */
  61.                                 /* make it easy to verify caller's selections */
  62.  
  63.     'INQUIRE HANGUP'            /* Initialize hangup flag */
  64.     QueuedFaxes = 0
  65.     Status = DoFaxOnDemand(Code)
  66.  
  67.     if Status = OK & QueuedFaxes > 0 then do
  68.         /* Build Operator string to transmit faxes and send them */
  69.         String = ''
  70.         do n = 0 to QueuedFaxes-1
  71.             String = String || '<X ' || Fax.n || '>'
  72.             end
  73.             
  74.         'OPERATOR <P SYSMSG:FaxHelp.sys>' String
  75.         
  76.         if rc = 0 then do
  77.             do n = 0 to QueuedFaxes-1
  78.                 FileString = statef(Fax.n)
  79.                 Note = word(FileString,8)
  80.                 if ~datatype(Note,'n') then
  81.                     Note = 0
  82.                 Note = Note + 1
  83.                 address command FileNote Fax.n Note
  84.                 end
  85.             end
  86.         end
  87.  
  88.     call reply(Pkt,1)           /* Hand control back to LineMan */
  89.     end
  90.  
  91. DoFaxOnDemand: procedure expose MaxFaxes QueuedFaxes Fax.
  92. /************************************************************************/
  93. /*    Purpose:                                                            */
  94. /*      Process caller's fax selections                                 */
  95. /*    Arguments:                                                          */
  96. /*      Code - Number of the first fax requested by caller              */
  97. /*    Return value:                                                       */
  98. /*      OK - Try to transmit                                            */
  99. /*      END - End the call                                              */
  100. /*  Comments:                                                           */
  101. /************************************************************************/
  102. Code = arg(1)
  103. do forever
  104.     do forever
  105.         'OPERATOR <P YouHaveEntered.sys>'
  106.         call Delay(25)
  107.         do i=1
  108.             Num = substr(Code,i,1)
  109.             if(Num = '') then
  110.                 leave
  111.             'SPEAK NUMBER' Num
  112.             end
  113.         call Delay(50)
  114.         'INQUIRE HANGUP'
  115.         if rc = 1 then
  116.             return END
  117.         Entry = PlayMessage('IfCorrect.sys',1,2)
  118.         if Entry = -1 then
  119.             return END
  120.         else if Entry = 1 then do
  121.             Duplicate = FALSE
  122.             do n = 0 to QueuedFaxes-1
  123.                 if Code = Fax.n then do
  124.                     Duplicate = TRUE
  125.                     leave;
  126.                     end
  127.                 end
  128.             if Exists(Code) & Duplicate = FALSE then do
  129.                 Fax.QueuedFaxes = Code
  130.                 QueuedFaxes = QueuedFaxes + 1
  131.                 end
  132.             else do
  133.                 'OPERATOR <P Invalid.sys>'
  134.                 call Delay(50)
  135.                 end
  136.             leave
  137.             end
  138.         else do
  139.             'OPERATOR <P Invalid.sys>'
  140.             call Delay(50)
  141.             leave
  142.             end
  143.         end
  144.  
  145.     if QueuedFaxes = MaxFaxes then  
  146.         return OK
  147.         
  148.     Code = PlayMessage('NextDocument.sys',2,3) 
  149.     if Code = '*' | Code = '' then
  150.         return OK
  151.     else if Code = -1 then
  152.         return END
  153.     end
  154.         
  155.     return
  156.  
  157. PlayMessage: procedure
  158. /************************************************************************/
  159. /*    Purpose:                                                            */
  160. /*      To play a sound file and perform basic error handling.          */
  161. /*    Arguments:                                                          */
  162. /*      Filename, Interdigit, Timeout                                   */
  163. /*    Return value:                                                       */
  164. /*      Caller's DTMF entry                                             */
  165. /*  Comments:                                                           */
  166. /************************************************************************/
  167.  
  168. do forever
  169.     'PLAYBACK "' || arg(1) || '"' arg(2) arg(3)
  170.     select
  171.       when rc = 0 then do
  172.           if result = 'RESULT' then
  173.               return ""
  174.           else
  175.               return result
  176.           end
  177.       when rc = 5 then      /* Pound entered, repeat message */
  178.           iterate
  179.       when rc = 4 then      /* Star entered */
  180.           return '*'    
  181.       otherwise             /* Terminate call */
  182.           return -1
  183.       end
  184.     end
  185.